Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

333
Views
Error: Failed to lookup view "main" in views directory "./views"

I have made the handlebars config in my index.js that I think was made correctly, but I continue to get this error where my main.hbs dont get found

Here's my code:

const express = require('express');
const mysql = require('mysql2');
const bodyParser = require('body-parser');
const { engine } = require('express-handlebars');
const app = express();


app.engine("handlebars", engine())
app.set("view engine", "handlebars")
app.set("views", "./views")

app.get('/', (req,res) => {
  res.render('main')
})

app.listen(3000, () => {
  console.log('Servidor na porta 3000')
})

Project structure is built this way:

.
├── index.js
└── views
    ├── home.handlebars
    └── layouts
        └── main.handlebars

Complete log error

Error: Failed to lookup view "main" in views directory "./views"
    at Function.render (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\application.js:580:17)
    at ServerResponse.render (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\response.js:1017:7)
    at C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\index.js:13:7
    at Layer.handle [as handle_request] (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\index.js:341:12)
    at next (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\index.js:275:10)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!